<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>

<a href="#/">首页</a>
<a href="#/user">用户</a>
<a href="#/mine">我的</a>

<div id="container">

</div>
<script>

  let container = document.getElementById('container');
  let router = {
    routes: {},
    router: function (path, callback) {
      this.routes[path] = callback
    },

    init: function () {
      let that = this;
      window.onhashchange = function () {
        let url = location.hash.replace('#','');
        console.log(that);
        that.routes[url]&&that.routes[url]()
        console.log(url);
      }
    }
  }

  router.router('/',function () {
    container.innerText = '这首页'

  })

  router.router('/user',function () {
    container.innerText = '用户'
  })

  router.router('/mine',function () {
    container.innerText = '我的'
  })
  router.init()




</script>
</body>
</html>
